package com.company.proxy.type3;

import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;
import java.lang.reflect.Method;

/**
 * 代理角色，CGLib动态代理方式
 */
public class ProxyByCglib implements MethodInterceptor {

    private Object realObject;

    public ProxyByCglib(Object realObject) {
        super();
        this.realObject = realObject;
    }


    @Override
    public Object intercept(Object object, Method method, Object[] args, MethodProxy proxy) throws Throwable {
        System.out.println("CGLib动态代理方式执行" +method.getName() + "方法，执行流程如下：");
        b1();
        Object result = method.invoke(realObject, args);
        b2();
        return result;
    }

    private void b1(){
        System.out.println("业务处理1");
    }

    private void b2(){
        System.out.println("业务处理2");
    }
}
